#!/bin/sh
CONFIG_BLK_CGROUP=y
CONFIG_BLK_DEV_THROTTLING=y
[ ! -d /cgroup ] && mkdir /cgroup/
[ ! -d /cgroup/mygroup ] && mkdir /cgroup/mygroup
mount -t tmpfs cgroup_root /cgroup/
mount -t cgroup -o blkio,cpu mygroup /cgroup/
cd /cgroup/
mkdir my001
mkdir my002

pid=`ps -ef|grep mysqld|grep 3306|awk '{print $2}'`  && echo $pid >  /cgroup/my001/tasks  && cat /proc/$pid/cgroup 

pid=`ps -ef|grep mysqld|grep 3406|awk '{print $2}'`  && echo $pid >  /cgroup/my002/tasks  && cat /proc/$pid/cgroup 



echo "8:16 5000"  > /cgroup/my001/blkio.throttle.write_iops_device 
echo "8:16 2000"  > /cgroup/my002/blkio.throttle.write_iops_device 
echo "4000" > /cgroup/my001/cpu.shares
echo "4000" > /cgroup/my002/cpu.shares
watch -n 1 cat /cgroup/my001/blkio.throttle.io_serviced


mysql -uroot -e "drop database sbtest;create database sbtest;" -S /u01/mysql2/run/mysql.sock &
mysql -uroot -e "drop database sbtest;create database sbtest;" -S /u01/mysql/run/mysql.sock &

./sysbench --test=tests/db/oltp.lua --max-time=72000000 --oltp-dist-type=uniform --max-requests=0 --mysql-user=monitor --mysql-password=monitor --mysql-table-engine=innodb --oltp-table-size=5000000 --oltp-tables-count=3 --oltp-range-size=90 --oltp-point-selects=120 --oltp-index-updates=50   --oltp-non-index-updates=50 --num-threads=50  --mysql-host=10.232.31.160  --mysql-port=3306 run  & 
./sysbench --test=tests/db/oltp.lua --max-time=72000000 --oltp-dist-type=uniform --max-requests=0 --mysql-user=monitor --mysql-password=monitor --mysql-table-engine=innodb --oltp-table-size=5000000 --oltp-tables-count=3 --oltp-range-size=90 --oltp-point-selects=120 --oltp-index-updates=50   --oltp-non-index-updates=50 --num-threads=50  --mysql-host=10.232.31.160  --mysql-port=3406 run &



a=0
while [ $a -eq  0 ];do 
iopssum=`mysqladmin -uroot extended-status -h127.0.0.1 -P3306  |grep 'Innodb_data_writes'|awk '{print $4}'`; 
iops=`expr  $iopssum  - $iopsold`; 
iopssum2=`mysqladmin -uroot extended-status -h127.0.0.1 -P3406 |grep 'Innodb_data_writes'|awk '{print $4}'`; 
iops2=`expr  $iopssum2  - $iopsold2`; 
echo "$iops   $iops2"  ; 
iopsold=$iopssum; 
iopsold2=$iopssum2; 
sleep 2; 
done



